<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

/// 应用公共文件


///重置密码，不指定密码则随机生成
function pro_reset_password($pw){
    if(empty($pw)){
        $pw = uniqid();
    }
    $pw_hash =  password_hash($pw, PASSWORD_BCRYPT, ['cost' => 12]);

    return array('password'=>$pw,'password_hash'=>$pw_hash);
}

///json_encode
function think_json_encode($params =array()){
    return json_encode($params,JSON_UNESCAPED_UNICODE);
}

///检测URL合法性
function cusCheckUrl($url){
    $n = preg_match("/^([a-zA-Z0-9_]+\\.)*([a-zA-Z0-9_]+){2}(:\d+)*$/",$url,$res_arr);
    ///不是url
    if(empty($res_arr) && $n == 0){
        return false;
    }
    ///是url
    return true;
}

///返回参数1对照参数2中不同的数据{白话来说结果是参数1内的数据}
function myfunction($a,$b)
{
    if ($a===$b)
    {
        return 0;
    }
    return ($a>$b)?1:-1;
}



///内部的一维数组不能完全相同所以删除重复项
function array_unique_fb($array2D) {
    $temp = array();
    //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
    foreach ($array2D as $v) {
        $v = join(",", $v);
        $temp[] = $v;

    }
    //去掉重复的字符串,也就是重复的一维数组
    $temp = array_unique($temp);
    //再将拆开的数组重新组装
    foreach ($temp as $k => $v) {
        $temp[$k] = explode(",", $v);

    }
    //返回结果
    return $temp;

}



///输出到自定义日志
function file_log($data = array(),$file = '1000'){
    file_put_contents('./'.$file.'.txt',print_r($data,true).PHP_EOL,FILE_APPEND);
}

///获取密码哈希
function getPwdHash($pwd){
    return password_hash($pwd, PASSWORD_DEFAULT);
}

///格式化打印变量
function loo($arr = array()){
    echo "<pre>";
    var_dump($arr);
    die;
}

///剔除变量中的单引号和反斜杠和横杠
function cus_character_filter($x){
    return str_replace(['\'','\\','-'],'',$x);
}

///获取当前的年份
function getYear(){
    return date("Y",time());
}